home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / dino / dino_bot.1 / examples / inc / map.c
Encoding:
C/C++ Source or Header  |  1991-03-10  |  1.6 KB  |  46 lines

  1. /* Copyright, 1990, Regents of the University of Colorado */
  2. /* This file contains functions for easy manipulation of DINO distributed
  3.  * arrays where each processor can have different sized pieces. */
  4.  
  5. typedef struct {
  6.   int left;            /* First element of home data */
  7.   int right;            /* Last element of home data */
  8.   int lover;            /* First element of overlap data */
  9.   int rover;            /* Last element of overlap data */
  10. } map_var;
  11.  
  12. /* This function computes a map variable for a given axis of a distributed
  13.  * array, given the size of the axis, the size of the environment axis it
  14.  * is mapped to, the index number for that axis, and the left and right
  15.  * overlaps. */
  16.  
  17. void set_map_var (n_, p_, i_, l_, r_, M_)
  18. int n_;            /* Size of the axis */
  19. int p_;            /* Size of the environment axis it's mapped to */
  20. int i_;            /* The index of this environment */
  21. int l_;            /* The left overlap of the mapping */
  22. int r_;            /* The right overlap of the mapping */
  23. map_var *M_;        /* The result variable */
  24.  
  25. {
  26.   M_->left = i_ * (n_/p_) + (i_ < n_%p_ ? i_ : n_%p_);
  27.   M_->right = (i_ + 1) * (n_/p_) + ((i_ + 1) < n_%p_ ? i_ : n_%p_ - 1);
  28.   M_->lover = (M_->left > l_ ? M_->left - l_ : 0);
  29.   M_->rover = (M_->right + r_ < n_ ? M_->right + r_ : n_ - 1);
  30. }
  31.  
  32. /* This function modifies a map variable to only use elements of the array
  33.  * which are within the given bounds. */
  34.  
  35. void limit_map_var (l_, r_, M_)
  36. int l_;            /* Left limit */
  37. int r_;            /* Right limit */
  38. map_var *M_;        /* The map variable */
  39.  
  40. {
  41.   if (M_->left < l_) M_->left = l_;
  42.   if (M_->lover < l_) M_->lover = l_;
  43.   if (M_->right > r_) M_->right = r_;
  44.   if (M_->rover > r_) M_->rover = r_;
  45. }
  46.